﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WHM3
{
    public class Shift
    {
        //1/8/2013::16:00
        private string _id;
        private string _start;
        private string _end;

        public Shift(string id, string start, string end)
        {
            this._id = id;
            this._start = start;
            this._end = end;
        }
        public string id
        {
            get { return this._id; }
            set { this._id = value; }
        }
        public string Start
        {
            get { return this._start; }
            set { this._start = value; }
        }

        public string End
        {
            get { return this._end; }
            set { this._end = value; }
        }

        public string toString()
        {
            return "start: " + Start + ", end: " + End;
        }

        public void print()
        {
            Console.WriteLine(ToString());
        }

        public string getStartYear()
        {
            char[] delimiterChars = { ':','/' };

            string[] words = _start.Split(delimiterChars);
            return words[2];
        }

        public string getEndYear()
        {
            if (_end == "") { return null; }
            char[] delimiterChars = { ':', '/' };

            string[] words = _end.Split(delimiterChars);
            return words[2];
        }

        public string getStartMonth()
        {
            char[] delimiterChars = { ':', '/' };

            string[] words = _start.Split(delimiterChars);
            return words[1];
        }

        public string getEndMonth()
        {
            if (_end == "") { return null; }
            char[] delimiterChars = { ':', '/' };

            string[] words = _end.Split(delimiterChars);
            return words[1];
        }

        public string getStartDay()
        {
            char[] delimiterChars = { ':', '/' };

            string[] words = _start.Split(delimiterChars);
            return words[0];
        }

        public string getEndDay()
        {
            if (_end == "") { return null; }
            char[] delimiterChars = { ':', '/' };

            string[] words = _end.Split(delimiterChars);
            return words[0];
        }

        public string getStartHour()
        {
            char[] delimiterChars = { ':', '/' };

            string[] words = _start.Split(delimiterChars);
            return words[4];
        }

        public string getEndHour()
        {
            if (_end == "") { return null; }
            char[] delimiterChars = { ':', '/' };

            string[] words = _end.Split(delimiterChars);
            return words[4];
        }

        public string getStartMin()
        {
            char[] delimiterChars = { ':', '/' };

            string[] words = _start.Split(delimiterChars);
            return words[5];
        }

        public string getEndMin()
        {
            if (_end == "") { return null; }
            char[] delimiterChars = { ':', '/' };

            string[] words = _end.Split(delimiterChars);
            return words[5];
        }

        public bool isInCorrectFormat()
        {
            if (Start == null) { return false; }

            char[] delimiterChars = { ':', '/' };

            string[] words = _start.Split(delimiterChars);
            if (words.Length != 6) { return false; }
            int j;
            for(int i = 0;i< 6;i++)
            {
                if (i == 3) { continue; }

                bool isNum = true;
                try{
                    int.Parse(words[i]);
                }
                catch{
                    isNum = false;
                }

                if (!isNum)
                {
                    return false;
                }
            }
            if (_end == "") { return true; }

            words = _end.Split(delimiterChars);
            if (words.Length != 6) { return false; }

            for (int i = 0; i < 6; i++)
            {
                if (i == 3) { continue; }

                bool isNum = true;
                try
                {
                    int.Parse(words[i]);
                }
                catch
                {
                    isNum = false;
                }

                if (!isNum)
                {
                    return false;
                }
            }

            return true;
        }
    }
}